<?php
/**
 * Created by PhpStorm.
 * Power by Mikkle
 * QQ:776329498
 * Date: 2017/4/18
 * Time: 9:49
 */

namespace app\erp\controller;

use app\base\controller\Rsa;


class Test
{

    public function index(){

        header('Content-Type:text/html;Charset=utf-8;');

        $string = isset($_GET['a']) ? $_GET['a'] : '测试123';

        //证书路径
        $pubfile = ROOT_PATH.'ssl/test.crt';
        $prifile = ROOT_PATH.'ssl/test.pem';
        //apache路径下的openssl.conf文件路径
        $openssl_config_path = "D:/phpStudy/Apache/conf/openssl.cnf";

        $rsa =new Rsa($pubfile,$prifile,$openssl_config_path);

        echo "<pre>";
        //生成签名
        echo "\n签名的字符串:\n$string\n\n";
        $sign = $rsa->sign($string);
        echo "\n生成签名的值:\n$sign";

        //验证签名
        $p=$rsa->verify($string, $sign);
        echo "\n验证签名的值:\n$p";


        //加密
        echo "\n\r加密的字符串:\n$string\n\n";
        $x = $rsa->encrypt($string);
        echo "\n生成加密的值:\n$x";

         //解密
        $y = $rsa->decrypt($x);
        echo "\n解密的值:\n$y";
        echo "</pre>";

        //创建新的密匙
        echo "\n创建新的密匙:\n";
        $rsa->buildNewKey();

    }
}